package Student;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class S_selmenu extends JFrame implements ActionListener {
    S_addc 增加选课界面;
    S_delc 删除选课界面;
    S_updatec 修改选课界面;
    S_selstu 学生查询界面;
    JPanel pCenter;
    CardLayout card = null;
    JLabel label = null;
    JMenuBar mb = new JMenuBar();//菜单栏
    JMenu m1 = new JMenu("选课管理");
    JMenuItem add1 = new JMenuItem("添加选课 ");
    JMenuItem updata1 = new JMenuItem("修改选课 ");
    JMenuItem delete1 = new JMenuItem("删除选课 ");
    //JMenu m4 = new JMenu("111");
    JMenu m2 = new JMenu("查询管理");
    JMenuItem 学生查询 = new JMenuItem("查询信息 ");
    JMenuItem m3 = new JMenuItem("退出");
    Font t = new Font("sanerif", Font.PLAIN, 12);

    public S_selmenu() {
        this.setTitle("学员信息");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.err.println("不能设置外观: " + e);
        }
        addMenu3();
        addMenu4();
        addJMenuBar();
        setJMenuBar(mb);
        label = new JLabel("培训课程管理系统", JLabel.CENTER);
        label.setFont(new Font("宋体", Font.BOLD, 36));
        label.setHorizontalTextPosition(SwingConstants.CENTER);
        label.setForeground(Color.black);
        m3.addActionListener(this);
        add1.addActionListener(this);
        delete1.addActionListener(this);
        updata1.addActionListener(this);
        学生查询.addActionListener(this);
        card = new CardLayout();
        pCenter = new JPanel();
        pCenter.setLayout(card);
        增加选课界面 = new S_addc();
        删除选课界面 = new S_delc();
        修改选课界面 = new S_updatec();
        学生查询界面 = new S_selstu();
        pCenter.add("欢迎界面", label);
        pCenter.add("增加选课界面", 增加选课界面);
        pCenter.add("删除选课界面", 删除选课界面);
        pCenter.add("修改选课界面", 修改选课界面);
        pCenter.add("学生查询界面", 学生查询界面);
        add(pCenter, BorderLayout.CENTER);
        validate();
        setVisible(true);

        setBounds(400, 150, 600, 380);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addWindowListener(new WindowAdapter() {//关闭程序时的操作
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        validate();
    }
    private void addJMenuBar() {
        mb.add(m1);
        mb.add(m2);
        mb.add(m3);
       // mb.add(m4);
    }
    private void addMenu4() {
        m2.add(学生查询);
        m2.setFont(t);
    }

    private void addMenu3() {
        m1.add(add1);
        m1.add(updata1);
        m1.add(delete1);
        m1.setFont(t);
    }
    public void actionPerformed(ActionEvent e) {
        Object obj = e.getSource();
        if (obj == m3) {
            System.exit(0);
        } else {
                    if (obj == add1) {
                        card.show(pCenter, "增加选课界面");
                    } else {
                        if (obj == delete1) {
                            card.show(pCenter, "删除选课界面");
                        } else {
                            if (obj == updata1) {
                                card.show(pCenter, "修改选课界面");
                            } else {
                                if (obj == 学生查询) {
                                    card.show(pCenter, "学生查询界面");
                                }
                            }
                        }
                }
        }
    }



    public static void main(String[] args) {
        new S_selmenu();

    }

}
